package com.leyou.item.web;

import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * - 请求方式：决定我们用GetMapping还是PostMapping
 * - 请求路径：决定映射路径
 * - 请求参数：决定方法的参数
 * - 返回值结果：决定方法的返回值
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryservice;

    /**
     * 根据父节点id查询商品分类
     * @param pid
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<List<Category>> queryCategoryByPid(@RequestParam("pid")Long pid){
        // 第一写法
        //return ResponseEntity.status(HttpStatus.OK).body(null);
        // 推荐写法
        return ResponseEntity.ok(categoryservice.queryCategoryListByPid(pid));
    }
}
